# Maintainer: Leonidas Spyropoulos <artafinde@archlinux.org>
# Contributor: David Runge <dvzrv@archlinux.org>
# Contributor: Luca Weiss <luca (at) z3ntu (dot) xyz>

pkgname=coeurl
pkgver=0.3.0
pkgrel=4
pkgdesc="A simple async wrapper around CURL for C++"
arch=("loong64" "x86_64")
url="https://nheko.im/nheko-reborn/coeurl"
license=('MIT')
depends=(gcc-libs glibc)
makedepends=(curl fmt libevent meson spdlog)
provides=(libcoeurl.so)
source=("https://nheko.im/nheko-reborn/coeurl/-/archive/v$pkgver/coeurl-v$pkgver.tar.gz"
         fix-curl-deprecation.patch::https://nheko.im/nheko-reborn/coeurl/-/commit/d926893007c353fbc149d8538a5762ca8384273a.patch
         fix-build-for-fmt10.patch::https://nheko.im/nheko-reborn/coeurl/-/commit/831e2ee8e9cf08ea1ee9736cde8370f9d0312abc.patch)
sha256sums=('48b07482364edcbed03e352f6b8b07e327c331eaa45707ad58e62930fa361382'
            'ec132d494795466a4492db9ac003dcd3e69b8cfb5297108fba214e6c5e3c56bb'
            '7f8ba5fa97a5d6206e648b12b1bce3213d6e4b7597299c789f21feee128b1840')
b2sums=('44c990a978f5970afacadff858502db5efd6709f8e5dcf43eeecfabda7f93262258a8a9fd7b1b411b8e28156657e02e1ceb532f9675265fe9f8143f4b07d844f'
        'ec794c7da51a1877518f94353f814f40251ccd04a29d70a0bdb277243be46a364c16e6559fbd0169f7747bbfc4d7152910e626ce87f584dc38713e9521195c3a'
        '26ce824f868792027d61849cd72540c7d121e2161b0d5a187f122b12e4f4d5c0b02c1dbfe63f9aa2873a1a76a42b108537eef9dadd5369fe5544690e146ed410')

prepare() {
  cd $pkgname-v$pkgver
  patch -Np1 -i $srcdir/fix-curl-deprecation.patch
  patch -Np1 -i $srcdir/fix-build-for-fmt10.patch
  sed -i 's/provides/provide/' subprojects/curl.wrap
}

build() {
  arch-meson $pkgname-v$pkgver build
  meson compile -C build
}

# Tests fail 
# - Needs cmake to properly detect doctest dependency https://github.com/doctest/doctest/issues/742
# - Needs to enable them with `-D tests=true`
# - Needs to execute ./scripts/run_testserver.sh and ./scripts/run_tls_testserver.sh prior to tests
# check() {
#   ninja test -C build
# }

package() {
  depends+=(
    curl libcurl.so
    fmt libfmt.so
    libevent libevent_{core,pthreads}-2.1.so
    spdlog libspdlog.so
  )

  meson install -C build --destdir "$pkgdir"
  install -vDm 644 $pkgname-v$pkgver/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}

# vim:set ft=sh sw=2 sts=2 et:
